package com.h2cloud.JUCTest.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Package: com.h2cloud.JUCTest.threadPool
 * @ClassName: newFixedThreadPool_Test
 * @Author: h2cloud
 * @CreateTime: 2022/5/31 12:34 上午
 * @Description:
 */

/**
 * 使用Executors的newFixedThreadPool工厂方法来创建线程池测试
 */
@Slf4j
public class newFixedThreadPool_Test {

	public static void main(String[] args) {
		ExecutorService pool = Executors.newFixedThreadPool(2, new ThreadFactory() {
			private AtomicInteger t = new AtomicInteger(1);
			// 设置线程工厂，自定义线程创建过程
			@Override
			public Thread newThread(Runnable r) {
				return new Thread(r, "Mythread_T" + t.getAndIncrement());
			}
		});

		pool.execute(() -> {
			log.info("1");
		});
		pool.execute(() -> {
			log.info("2");
		});
		pool.execute(() -> {
			log.info("3");
		});


	}

}
